package com.vue.vuedemo.controller;

import com.vue.vuedemo.map.UserMapper;
import com.vue.vuedemo.pojo.User;
import com.vue.vuedemo.viewpojo.ResList;
import com.vue.vuedemo.viewpojo.ResObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class LoginController {

	@Autowired
	UserMapper userMapper;
	
    @PostMapping("/login")
    public ResObject getimgcategory(HttpServletResponse response, HttpServletRequest request){
        response.setHeader("Access-Control-Allow-Origin", "*");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        
        System.err.println(username);
        System.err.println(password);
        
        User user = userMapper.userLogin(username, password);
        
        ResObject<User> res = new ResObject();
        
        if(user != null) {
        	
        	res.setMessage(user);
        	res.setStatus(0);
        	return res;
        }
        
        res.setStatus(-1);
       
        return res;
    }

}
